/**
 * 
 */
package com.util;

import java.util.Map.Entry;
import java.util.Properties;

public class PropertiesCompatible extends Loggable {

	protected Properties props;
	
	public PropertiesCompatible()
	{
		this.props = new Properties();
	}
	
	public String getProps()
	{
		String p = "";
		for (Entry<Object, Object> e : props.entrySet())
		{
			if (p.length() >0)
				p += "&";
			p += (String) e.getKey() + "=" + (String) e.getValue();
		}
		return p;
	}
	
	public void setProps(String props)
	{
		this.props = new Properties();
		String[] ss = props.split("&");
		for (String s : ss)
		{
			s = s.trim();
			if (s.length() == 0)
				continue;
			
			String[] si = s.split("=", 2);
			if (si.length == 2)
				this.props.setProperty(si[0], si[1]);
			else
				this.props.setProperty(si[0], "");
		}
	}
	
	public void setProps(String key, String value)
	{
		this.props.setProperty(key, value);
	}
	
	public String getProps(String key)
	{
		return this.props.getProperty(key);
	}
	
	public Properties getProperties()
	{
		return this.props;
	}
	
	public void setProperties(Properties props)
	{
		this.props = props;
	}
}
